﻿using Assets.Core.Common.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace Nucleic.Web.Filters
{
    public class MyExceptionFilterAttribute: ExceptionFilterAttribute
    {
        private readonly ILogger<MyExceptionFilterAttribute> _logger;

        public MyExceptionFilterAttribute(ILogger<MyExceptionFilterAttribute> logger)
        {
            _logger = logger;
        }
        public override void OnException(ExceptionContext context)
        {
            _logger.LogError(context.Exception.ToString());
            var resule = new JsonResult(Result.fail(context.Exception.Message));
            resule.StatusCode = 200;
            context.Result = resule;
        }
    }
}
